// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import Vant from 'vant';
import 'vant/lib/index.css';

// 配置请求相关参数
axios.defaults.baseURL = "http://127.0.0.1"
axios.defaults.headers.common['Content-Type'] = 'application/json'
axios.defaults.withCredentials = true;//携带cookie
// 拦截请求的结果，判断是否存在登录超时
axios.interceptors.response.use((res) => {
  let data = res.data
  console.log("data:", data)
  if (data.code === 502) { // 登录超时
    router.push({
      path: '/login'
    })
  } else {
    return res.data
  }
}, (err) => {
  return Promise.reject(err)
})

Vue.config.productionTip = false
Vue.use(Vant);
Vue.prototype.$http = axios
Date.prototype.Format = function (fmt) {
  let o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    "S": this.getMilliseconds() //毫秒
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (let k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k])
      : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
})
